﻿using Desktop.Library;
using System.Threading;
using System.Windows;
using System.Windows.Media;

namespace Desktop.Dialogs
{
    /// <summary>
    /// Interaction logic for LoginWindow.xaml
    /// </summary>
    public partial class LoginWindow : Window
    {
        #region Constructors

        private LoginWindow()
        {
            InitializeComponent();
            Background = new SolidColorBrush(SystemColors.ControlColor);
        }

        #endregion

        #region Properties

        protected string Username { get; set; }
        protected string Password { get; set; }

        #endregion

        #region Methods

        public static void Login()
        {
            LoginWindow wdo = new LoginWindow();
            if (wdo.ShowDialog().GetValueOrDefault(false))
            {
                GoogleIdentity identity = new GoogleIdentity(wdo.Username, wdo.Password);
                Thread.CurrentPrincipal = new GooglePrincipal(identity);
            }
        }

        #endregion

        #region Event Handlers

        private void loginButton_Click(object sender, RoutedEventArgs e)
        {
            Username = usernameTextBox.Text;
            Password = passwordTextBox.Password;

            DialogResult = true;
            Close();
        }

        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }

        #endregion
    }
}